<template>
    <div>
        <el-row :gutter="10" style="margin-bottom: 40px;">
            <el-col :span="6">
                <el-card>
                    <div style="color: #409EFF;"><i class="el-icon-user-solid"></i> 用户总数</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold;">74671</div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card>
                    <div style="color: #E6A23C;"><i class="el-icon-s-custom"></i> 教师总数</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold;">3491</div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card>
                    <div style="color: #67C23A;"><i class="el-icon-map-location"></i> 学校建筑面积</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold;">2760,000平方米</div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card>
                    <div style="color: #F56C6C;"><i class="el-icon-school"></i> 校区总数</div>
                    <div style="padding: 10px 0; text-align: center; font-weight: bold;">6</div>
                </el-card>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
                <el-card id="main" style="width: 500px; height: 450px;"></el-card>
            </el-col>
            <el-col :span="12">
                <el-card id="pie" style="width: 500px; height: 450px;"></el-card>
            </el-col>
        </el-row>
        
        
    </div>
</template>

<script>
    import * as echarts from 'echarts';

    export default {
        name: "Home",
        data() {
            return {

            }
        },
        // 页面元素渲染之后再触发
        mounted() {
            // 折线图+柱状图
            var option = {
                title: {
                    text: '各学历学生数量统计',
                    subtext: '趋势图',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                xAxis: {
                    type: 'category',
                    data: ["专科生", "本科生", "硕士生", "博士生"]
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                        name: "",
                        data: [],
                        type: 'bar'
                    },
                    {
                        name: "",
                        data: [],
                        type: 'line'
                    },
                    {
                        name: "",
                        data: [],
                        type: 'bar'
                    },
                ]
            };
            // 饼图
            var pieOption = {
                title: {
                    text: '各学历学生数量统计',
                    subtext: '比例图',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [{
                    type: 'pie',
                    radius: '60%',
                    data: [],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }]
            };
            var chartDom = document.getElementById('main');
            var myChart = echarts.init(chartDom);
        
            var pieChartDom = document.getElementById('pie');
            var pieMyChart = echarts.init(pieChartDom);
            

            this.request.get("/echarts/members").then(res => {
                // option.xAxis.data = res.data.x
                option.series[0].data = res.data
                option.series[1].data = res.data
                option.series[2].data = [6,3,5,8]
                myChart.setOption(option);

                pieOption.series[0].data = [
                    {name: "专科生", value: res.data[0]},
                    {name: "本科生", value: res.data[1]},
                    {name: "硕士生", value: res.data[2]},
                    {name: "博士生", value: res.data[3]},
                ]
                pieMyChart.setOption(pieOption)
            })
        },
    }
</script>

<style scoped>

</style>